package com.gery.tn.backend.service.ini;

import com.gery.tn.backend.model.Appointment;
import com.gery.tn.backend.service.AppointmentService;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;



public final class IniAppointmentService implements AppointmentService {

    private INIFile ini;
    
    
    public IniAppointmentService() throws IOException {
        ini = new INIFile("C:/Users/Gery/Documents/NetBeansProjects/TiaNails/src/com/gery/tn/backend/service/ini/db.ini");
    }
    
    
    
    
    @Override
    public void saveAppointment(Appointment appointment) {
        Calendar appDate = appointment.getDate();
        String note = appointment.getNote();
        String dateStr = toString(appDate);
        //int appNr = ini.getIntegerProperty(client, "datenr");
        //appNr++;
        //ini.setIntegerProperty(client, "datenr", appNr, "");
        if ("".equals(note)) {
            note = "Details...";
        }
        //ini.setStringProperty(client, "date" + appNr, dateStr + "#####" + note, "");
        ini.save();
    }
    

    public Appointment getAppointment(long id) {
//        //int appNr = ini.getIntegerProperty(client, "datenr");
//        //List<Appointment> tempList = new ArrayList<>(appNr);
//        //for (int i=0; i<appNr; i++) {
//            //String appStr = ini.getStringProperty(client, "date" + (i+1));
//            //String[] appComp = appStr.split("#####");
//            //if ("".equals(appComp[1])) {
//                appComp[1] = "Details...";
//            }
//            tempList.add(new Appointment(parseDate(appComp[0]), appComp[1]));
//            //tempList.get(i).setNr(Long.i);
//        }
        return null;
    }
    @Override
    public void removeAppointment(long id) {
        
    }
    @Override
    public List<Appointment> getAllAppointments() {
        return null;
    }
    
    
    public Calendar parseDate(String date) {
        Calendar tempDate = GregorianCalendar.getInstance();
        String[] dateComp = date.split("/");
        tempDate.set(Calendar.YEAR, Integer.parseInt(dateComp[0]));
        tempDate.set(Calendar.MONTH, Integer.parseInt(dateComp[1]));
        tempDate.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateComp[2]));
        tempDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateComp[3]));
        tempDate.set(Calendar.MINUTE, Integer.parseInt(dateComp[4]));
        return tempDate;
    }
    public String toString(Calendar date) {
        String tempString = "";
        tempString = tempString + date.get(Calendar.YEAR) + "/";
        tempString = tempString + date.get(Calendar.MONTH) + "/";
        tempString = tempString + date.get(Calendar.DAY_OF_MONTH) + "/";
        tempString = tempString + date.get(Calendar.HOUR_OF_DAY) + "/";
        tempString = tempString + date.get(Calendar.MINUTE);
        return tempString;
    }

}
